package com.shopx.cm.controller;

import com.shopx.base.anno.ShopxCheckParamAnno;
import com.shopx.base.anno.ShopxParamAnno;
import com.shopx.base.controller.BaseController;
import com.shopx.base.dto.Result;
import com.shopx.base.exception.ShopxException;
import com.shopx.base.utils.ResultUtil;
import com.shopx.cm.bean.MaterialSaleDTO;
import com.shopx.cm.bean.MaterialSaleReqDTO;
import com.shopx.cm.service.IMaterialSaleService;
import com.shopx.cmm.DTO.PageDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Slf4j
@RequestMapping(value = "/materialSale")
public class MaterialSaleController extends BaseController {
    @Resource
    private IMaterialSaleService materialSaleService;

    /**
     * 材料销售数据统计
     * @param dto
     * @return
     * @throws ShopxException
     */
    @PostMapping(value = "/getSalesByMaterial")
    @ShopxParamAnno
    @ShopxCheckParamAnno
    public Result<PageDTO> getSalesByMaterial(@RequestBody MaterialSaleReqDTO dto) throws ShopxException {
        PageDTO<MaterialSaleDTO> pageDTO = materialSaleService.getSalesByMaterial(dto);
        return ResultUtil.ok(pageDTO);
    }

    /**
     * 材料品牌销售数据统计
     * @param dto
     * @return
     * @throws ShopxException
     */
    @PostMapping(value = "/getSalesByBrand")
    @ShopxParamAnno
    @ShopxCheckParamAnno
    public Result<PageDTO> getSalesByBrand(@RequestBody MaterialSaleReqDTO dto) throws ShopxException {
        PageDTO<MaterialSaleDTO> pageDTO = materialSaleService.getSalesByBrand(dto);
        return ResultUtil.ok(pageDTO);
    }

    /**
     * 材料实付销售数据统计
     * @param dto
     * @return
     * @throws ShopxException
     */
    @PostMapping(value = "/getSalesByCode")
    @ShopxParamAnno
    @ShopxCheckParamAnno
    public Result<PageDTO> getSalesByCode(@RequestBody MaterialSaleReqDTO dto) throws ShopxException {
        PageDTO<MaterialSaleDTO> pageDTO = materialSaleService.getSalesByCode(dto);
        return ResultUtil.ok(pageDTO);
    }

    /**
     * 材料月度售数据统计
     * @param dto
     * @return
     * @throws ShopxException
     */
    @PostMapping(value = "/getSalesByMth")
    @ShopxParamAnno
    @ShopxCheckParamAnno
    public Result<PageDTO> getSalesByMth(@RequestBody MaterialSaleReqDTO dto) throws ShopxException {
        PageDTO<MaterialSaleDTO> pageDTO = materialSaleService.getSalesByMth(dto);
        return ResultUtil.ok(pageDTO);
    }

    /**
     * 根据分组查询
     * @param dto
     * @return
     * @throws ShopxException
     */
    @PostMapping(value = "/querySalesByGroupList")
    @ShopxParamAnno
    @ShopxCheckParamAnno
    public Result<MaterialSaleDTO> querySalesByGroupList(@RequestBody MaterialSaleReqDTO dto) throws ShopxException {
        List<MaterialSaleDTO> list = materialSaleService.querySalesByGroupList(dto);
        return ResultUtil.ok(list);
    }

    @PostMapping(value = "/querySalesListByCode")
    @ShopxParamAnno
    @ShopxCheckParamAnno
    public Result<PageDTO> querySalesListByCode(@RequestBody MaterialSaleReqDTO dto) throws ShopxException {
        List<MaterialSaleDTO> list = materialSaleService.querySalesListByCode(dto);
        return ResultUtil.ok(list);
    }
}
